package cq.zhcqk.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import cq.zhcqk.R;
import cq.zhcqk.app;
import cq.zhcqk.base.BaseActivity;
import cq.zhcqk.util.AsyncHttpClientUtils;
import cq.zhcqk.util.SpUtil;

/**
 * Created by zhangle on 2017/12/10.
 */
public class MineSettingActivity extends BaseActivity implements View.OnClickListener{

    private LinearLayout mine_pwd;
    private Button out;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_setting);
        mSharedPreferences = SpUtil.getSpBykey(context, SpUtil.TOKEN);
        initBack();
        mine_pwd = (LinearLayout) findViewById(R.id.mine_pwd);
        out = (Button) findViewById(R.id.out);

        mine_pwd.setOnClickListener(this);
        out.setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    private void initBack(){
        ImageView back = (ImageView) findViewById(R.id.header_back);
        TextView title = (TextView) findViewById(R.id.header_text);
        title.setText("设置");
        back.setOnClickListener(this);
    }

    private void loginOut(){
        app.isLogin = false;
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString("token","1");
        editor.commit();
        AsyncHttpClientUtils.removeHeader();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.header_back:
                finish();
                break;
            case R.id.mine_pwd:
                Intent intent = new Intent(this,Register2Activity.class);
                intent.putExtra("sourse","update");
                startActivity(intent);
                overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
                break;
            case R.id.out:
                if(!app.isLogin){
                    Toast.makeText(context,"请先登录",Toast.LENGTH_SHORT).show();
                    return;
                }
                loginOut();
                finish();
                break;
        }
    }
}
